package CustomProviders
{
	import LifeParserCommon.ServiceInterface;
	
	import mx.collections.ArrayCollection;
	import mx.formatters.*;
	
	public class FBProvider implements ServiceInterface
	{
		private  var dataArray:ArrayCollection = new ArrayCollection();
		
		public function FBProvider(rawData:Object)
		{
			super();
			dataArray = rawData as ArrayCollection; 
			//formatDataCollection(rawData);
		}
		
		public function formatDataCollection(data: Object):void
		{									
		/*	for (var idx:int = 0; idx < dataInArray.length; idx++)
			{								
				var intdate:int = dataInArray.getItemAt(idx,0).created_time as int; 
				var msgDate:Date = new Date(intdate * 1000);
				var mmddyy:DateFormatter = new DateFormatter();
				var hhmm:DateFormatter = new DateFormatter();	
				
				mmddyy.formatString = "MM/DD/YY";							
				hhmm.formatString = "H:N";
				
				dataArray.addItem({ 
					time: hhmm.format(msgDate),
					date: mmddyy.format(msgDate),
					message: dataInArray.getItemAt(idx).message,
					info: "Posts"});
			} */
		}
		
		public function formatDataForInterface(request: String): ArrayCollection
		{			
			var requestLabel: String			            = "label" + request;
//			var splitArray: Array							= dataArray[ idx ][ "info" ].split(' ');
			
			for (var idx:int = 0; idx < dataArray.length; idx++){
				if(this.dataArray[ idx ][ requestLabel ] == undefined)
				{
					var dataObj: Object								= this.dataArray[ idx ];
					dataObj[ requestLabel ]							= "Posts";
					dataObj[ requestLabel + "Name" ]				= "Actor";
					dataObj[ requestLabel + "displayKeys" ]			= "date,time," + requestLabel +",message";
					dataObj[ "message" ]							= "hi";//dataArray.getItemAt(idx).message;
					dataObj[ requestLabel + "frequencyParameter" ]	= "Actor";
					this.dataArray[ idx ]							= dataObj;
				}
			}		
			return dataArray;			
		}
		
		public function formatDataForSentiments(request: String): ArrayCollection
		{
			var idx: int						= 0;
			var requestLabel: String			= "label" + request;
			
			for (idx = 0; idx < this.dataArray.length; idx++)
			{				
				if(this.dataArray[ idx ][ requestLabel ] == undefined)
				{
					this.dataArray[ idx ][ requestLabel ]	= "Sentiment Polarity";
				}
			}
			
			return this.dataArray;			
		}
		
		public function getHourDataProvider(): ArrayCollection
		{
			return this.dataArray;
		}
		
		public function getDayDataProvider(): ArrayCollection
		{			
			return this.formatDataForInterface("Day");
		}
		
		public function getMonthDataProvider(): ArrayCollection
		{
			return this.dataArray;
		}
		
		public function getActivityDataProvider(): ArrayCollection
		{
			return this.formatDataForInterface("Day");
		}
		
		public function getSentimentDataProvider(): ArrayCollection
		{
			return this.formatDataForSentiments("Senti");
		}
		
		public function getMonthFromDate(date: String): int
		{
			return parseInt(date.split('/')[1]);
		}
		
		public function doFormatTimeToHour(time:String): Number
		{
			var hour:int		= 0;
			var min:int			= 0;
			var resHour: Number	= 0.0;
			var timeArray:Array	= time.split(":");
			
			hour	= parseInt(timeArray[0]);
			min		= parseInt(timeArray[1]);
			resHour	= (hour+min/60);
			
			return resHour;
		}
	}
}